/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PaymentReviewView.java
 *
 * Created on Apr 9, 2010, 9:40:48 PM
 */
package ticketmaster.presentation.customer.purchase;

import javax.swing.JFrame;
import ticketmaster.accounting.PointsManager;
import ticketmaster.businesslogic.PremiumCustomerController;
import ticketmaster.businessobject.Customer;
import ticketmaster.dataobject.Order;
import ticketmaster.dataobject.PremiumCustomer;
import ticketmaster.presentation.customer.CustomerBasePanel;
import ticketmaster.util.StringHelper;

/**
 *
 * @author Wei Liu
 */
public class PaymentReviewView extends CustomerBasePanel
{

    private Order order;
    private PremiumCustomer premiumCustomer;

    /** Creates new form PaymentReviewView */
    public PaymentReviewView(double rawCost, double tax)
    {
        initComponents();
        setData(rawCost, tax);
    }

    private void setData(double rawCost, double tax)
    {
        this.lblFare.setText(StringHelper.formatPrice(rawCost));
        this.lblTax.setText(StringHelper.formatPrice(tax));
        this.lblTotal.setText(StringHelper.formatPrice(rawCost + tax));

        PremiumCustomerController controller = new PremiumCustomerController();
        premiumCustomer = controller.getPremiumCustomer(this.getUser());
        if (premiumCustomer != null)
        {
            premiumCustomer.setPoints(premiumCustomer.getPoints() + PointsManager.calculatePoints(rawCost + tax));
            this.lblPoints.setText("You will earn " + PointsManager.calculatePoints(rawCost + tax) + " points for this purchase");
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        lblFare = new javax.swing.JLabel();
        lblTax = new javax.swing.JLabel();
        btnNext = new javax.swing.JButton();
        lblTotal = new javax.swing.JLabel();
        lblPoints = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ticketmaster.TicketMasterApp.class).getContext().getResourceMap(PaymentReviewView.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 25, 230, 30));

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 60, 270, -1));

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, 110, 30));

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 180, 100, 30));

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, 250, 30));

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N
        add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, 240, 30));

        jSeparator2.setForeground(resourceMap.getColor("jSeparator2.foreground")); // NOI18N
        jSeparator2.setName("jSeparator2"); // NOI18N
        add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 180, 530, 10));

        jSeparator3.setName("jSeparator3"); // NOI18N
        add(jSeparator3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, 530, 10));

        jSeparator4.setName("jSeparator4"); // NOI18N
        add(jSeparator4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, 530, 10));

        lblFare.setFont(resourceMap.getFont("lblFare.font")); // NOI18N
        lblFare.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblFare.setText(resourceMap.getString("lblFare.text")); // NOI18N
        lblFare.setName("lblFare"); // NOI18N
        add(lblFare, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 180, 130, 30));

        lblTax.setFont(resourceMap.getFont("lblTax.font")); // NOI18N
        lblTax.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblTax.setText(resourceMap.getString("lblTax.text")); // NOI18N
        lblTax.setName("lblTax"); // NOI18N
        add(lblTax, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 240, 110, 30));

        btnNext.setFont(resourceMap.getFont("btnNext.font")); // NOI18N
        btnNext.setText(resourceMap.getString("btnNext.text")); // NOI18N
        btnNext.setName("btnNext"); // NOI18N
        btnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextActionPerformed(evt);
            }
        });
        add(btnNext, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 420, 150, 50));

        lblTotal.setBackground(resourceMap.getColor("lblTotal.background")); // NOI18N
        lblTotal.setFont(resourceMap.getFont("lblTotal.font")); // NOI18N
        lblTotal.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblTotal.setText(resourceMap.getString("lblTotal.text")); // NOI18N
        lblTotal.setName("lblTotal"); // NOI18N
        add(lblTotal, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 300, 130, 30));

        lblPoints.setFont(resourceMap.getFont("lblPoints.font")); // NOI18N
        lblPoints.setText(resourceMap.getString("lblPoints.text")); // NOI18N
        lblPoints.setName("lblPoints"); // NOI18N
        add(lblPoints, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 360, 370, 30));
    }// </editor-fold>//GEN-END:initComponents

    private void btnNextActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnNextActionPerformed
    {//GEN-HEADEREND:event_btnNextActionPerformed
        PaymentView pv = new PaymentView();
        pv.setOrder(order);
        pv.setPremiumCustomer(premiumCustomer);
        pv.setCart(this.getCart());
        pv.setBookedTickets(this.getBookedTickets());
        pv.setPnlParent(this.getPnlParent());
        if (this.getMainFrame() != null)
        {
            pv.setMainFrame(this.getMainFrame());
        }
        this.getPnlParent().removeAll();
        this.getPnlParent().add(pv);
        this.getPnlParent().validate();
        this.getPnlParent().repaint();
    }//GEN-LAST:event_btnNextActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnNext;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JLabel lblFare;
    private javax.swing.JLabel lblPoints;
    private javax.swing.JLabel lblTax;
    private javax.swing.JLabel lblTotal;
    // End of variables declaration//GEN-END:variables

    private static void createAndShowGUI()
    {

        //Create and set up the window.
        JFrame frame = new JFrame("demo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        PaymentReviewView newContentPane = new PaymentReviewView(23.4, 3);
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args)
    {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {

            public void run()
            {
                createAndShowGUI();
            }
        });
    }

    /**
     * @return the order
     */
    public Order getOrder()
    {
        return order;
    }

    /**
     * @param order the order to set
     */
    public void setOrder(Order order)
    {
        this.order = order;
    }

    /**
     * @return the premiumCustomer
     */
    public PremiumCustomer getPremiumCustomer()
    {
        return premiumCustomer;
    }

    /**
     * @param premiumCustomer the premiumCustomer to set
     */
    public void setPremiumCustomer(PremiumCustomer premiumCustomer)
    {
        this.premiumCustomer = premiumCustomer;
    }
}
